package com.zlm.design.observer;

/**
 * @author zlm
 * @date 2025/5/23
 */
public class Main {

    //观察者模式 --> 事件产生者直接去监听消息
    //发布订阅 --> 事件产生者 --> 总线 --> 监听器
    public static void main(String[] args) throws InterruptedException {

        TVStation tvStation = new TVStation();

        WeatherStation station = new WeatherStation(tvStation);

        User tom = new User("tom", info -> {
            if ("晴天".equals(info)) {
                System.out.println("晴天可以出去玩");
            } else {
                System.out.println("tom在家玩");
            }
        });

        User jerry = new User("jerry", info -> {
            if("晴天".equals(info)) {
                System.out.println("钻洞");
            }
        });
        tvStation.subscribe(tom, WeatherUpdateEvent.class);
        tvStation.subscribe(jerry, WeatherUpdateEvent.class);
        station.start();


    }
}
